import elementEnLocale from 'element-plus/es/locale/lang/en'
import elementZnLocale from 'element-plus/es/locale/lang/zh-cn'
import { createI18n } from 'vue-i18n'

import en from './en'
import zh from './zh'

export const lang = {
  'zh-CN': 'zh',
  'en-US': 'en',
  'en-GB': 'en',
  en: 'en'
}[navigator.language]

export const messages = {
  en: {
    ...en,
    ...elementEnLocale
  },
  zh: {
    ...zh,
    ...elementZnLocale
  }
}

const localData = {
  legacy: false,
  globalInjection: true,
  locale: lang,
  messages
}

const i18n = createI18n(localData)

// 切换语言
export const changeLanguage = (locale) => {
  i18n.global.locale.value = locale
}

export default i18n
